// pages/insurance/insurance.js
const app = getApp()
const constant = require('../../constant');
Page({

  /**
   * 页面的初始数据
   */
  data: {
    insurance: [],
    insurance_yf: [],
    insurance_yw: []
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.getInsurance();
    this.getInsuranceYf();
    this.getInsuranceYw();
  },
  //获取最热保险产品
  getInsurance(){
    let that = this;
    app.get('Goods/gethottestproduct', {
      type: '3,8,9'
    }, function (res) {
      if (res.code == 200 && res.data != null) {
        res.data.goods_img = constant.config.host + res.data.goods_img;
        that.setData({
          insurance: res.data,
        })
      }
    })
  },
  //获取保运费产品列表
  getInsuranceYf() {
    let that = this;
    app.get('Goods/getproductlist', {
      type: '8'
    }, function (res) {
      if (res.code == 200 && res.data.data_list.length > 0) {
        for (var i = 0; i < res.data.data_list.length; i++) {
          res.data.data_list[i].goods_img = constant.config.host + res.data.data_list[i].goods_img;
        }
        that.setData({
          insurance_yf: res.data.data_list,
        })
      }
    })
  },
  //获取保意外产品列表
  getInsuranceYw() {
    let that = this;
    app.get('Goods/getproductlist', {
      type: '9'
    }, function (res) {
      if (res.code == 200 && res.data.data_list.length > 0) {
        for (var i = 0; i < res.data.data_list.length; i++) {
          res.data.data_list[i].goods_img = constant.config.host + res.data.data_list[i].goods_img;
        }
        that.setData({
          insurance_yw: res.data.data_list,
        })
      }
    })
  },
  //立即投保跳转
  toInsuranceDetails: function (event) {
    var id = event.currentTarget.dataset.id;
    wx.navigateTo({
      url: '../insuranceDetails/insuranceDetails?goods_id=' + id
    })
  },
  //客服理赔跳转
  toIndemnity: function () {
    wx.navigateTo({
      url: '../Indemnity/Indemnity'
    })
  },
  //投保记录跳转
  toInsuranceList: function () {
    wx.navigateTo({
      url: '../insuranceList/insuranceList'
    })
  },
  //我的理赔
  toInsuranceSettleList: function() {
    wx.navigateTo({
      url: '../insuranceSettleList/insuranceSettleList'
    })
  },
  //投保攻略跳转
  toInsure: function () {
    wx.navigateTo({
      url: '../insure/insure'
    })
  },
  //我的理赔跳转
  toMyInsuranceDetails: function () {
    wx.navigateTo({
      url: '../insuranceDetails/insuranceDetails'
    })
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})